<template>
  <div style="padding-bottom: 50px;">
    <van-cell-group>
      <van-cell :title="order.address.name" :value="order.address.fullAddress" size="large"
                :label="order.address.phone"></van-cell>
    </van-cell-group>

    <van-cell-group>
      <van-cell title="商品价格" :value="order.price"></van-cell>
      <van-cell title="运费" :value="order.exFee"></van-cell>
    </van-cell-group>

    <van-card
      v-for="goods in order.cartGoodsList"
      :key="goods.id"
      :num="goods.count"
      :price="goods.realPrice + '*' + goods.count +'='+goods.cartGoodsPrice"
      :desc="goods.description"
      :title="goods.goodsName + ' - ' + goods.skuName"
      :thumb="goods.skuThumb">
    </van-card>

    <van-submit-bar
      :price="formatNumber(order.totalPrice)"
      button-text="提交订单"
      @submit="onSubmit">
    </van-submit-bar>
  </div>
</template>
<script>
  import axios from "axios"
  import qs from "qs"
  import url from "../assets/app/url"
  import {SubmitBar, Notify} from 'vant';

  import appFunc from "../assets/app/func"

  export default {
    data() {
      return {
        order: appFunc.getOrder()
      }
    },
    created: function () {
      appFunc.login();
      appFunc.isLogin();
    },
    methods: {
      onSubmit: function () {
        let data = {
          address: this.order.address,
          user: appFunc.getUserinfoCache(),
          goodsList: this.order.cartGoodsList,
          platform:appFunc.getPlatform()
        };
        axios.post(url.OrderCreate, qs.stringify(data)).then(req => {
          let info = req.data;
          if (info.status) {
            Notify({
              message: "订单创建成功",
              duration: 1000,
              background: '#1989fa'
            });
            appFunc.platformPay(info.info);
          } else {
            Notify({
              message: info.info,
              duration: 1000,
            });
          }
        })
      },
      formatNumber: function (number) {
        return Number(number) * 100
      }
    }
  }
</script>
<style>
  body {
    background-color: #f4f4f4;
  }

  .van-cell-group {
    margin-bottom: 8px;
  }

  .van-cell__label {
    margin-top: 5px;
    line-height: .48rem;
    font-size: .1rem !important;
    color: #b4282d;
  }
</style>
